package cn.qdu.service;

import cn.qdu.dao.CommentDao;
import cn.qdu.model.Comment;

import java.sql.SQLException;
import java.util.List;

public class CommentService {
    private CommentDao commentDao;

    public CommentService(CommentDao commentDao) {
        this.commentDao = commentDao;
    }

    public boolean addComment(Comment comment) {
        try {
            return commentDao.addComment(comment);
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

    public boolean deleteComment(int commentId, String userId) {
        try {
            return commentDao.deleteComment(commentId, userId);
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

    public List<Comment> getCommentsByPostId(int postId) {
        try {
            return commentDao.getCommentsByPostId(postId);
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }

    public int getCommentCountByPostId(int postId) {
        try {
            return commentDao.getCommentCountByPostId(postId);
        } catch (SQLException e) {
            e.printStackTrace();
            return 0;
        }
    }
}